home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18522 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: composer.inav.net!news
  2. From: Aaron Plattner <aaronp@biovax.biology.uiowa.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Char to int??
  5. Date: Sat, 20 Apr 1996 12:29:15 -0500
  6. Organization: Internet Navigator, Inc.
  7. Message-ID: <31791EEB.5E5F@biovax.biology.uiowa.edu>
  8. References: <4ai0ov$l88@nosy.bart.nl> <DpzMrD.F8@pgh.nauticom.net>
  9. NNTP-Posting-Host: dip18.inav.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01Gold (Win95; I)
  14.  
  15. >Steven van den Berg (painless@bart.nl) wrote:
  16. >: Can somebody please tell me how you can covert a char to an int. I
  17. >: want to convert a char like "a" to the scancode of a and put that into
  18. >: an int.
  19. >
  20. >Anotherway that can work, depending on what you need...try using
  21. >
  22. >{
  23. >  char c[]="car";
  24. >  int Crap;
  25. >
  26. > Crap=atoi(c);
  27. >}
  28. >
  29. >Don't ask me what library you need.
  30. >-Jamshid
  31.  
  32. I don't quite agree with you.  You would use atoi to do something like this:
  33.  
  34. {
  35.     char c[]="42";
  36.     int x;
  37.     x=atoi(c);
  38.     /* x now equals 42 */
  39. }
  40.  
  41. What you can do is try a type-cast.  For example:
  42.  
  43. {
  44.     char c='a';
  45.     int x;
  46.     x=(int)c;
  47.     /* x now equals the ascii value of "a" */
  48. }
  49.  
  50. --Aaron Plattner
  51.  
  52. P.S. atoi() is in the stdlib.h include file
  53.